package com.situ.javase.week2.day4;

import java.util.ArrayList;
import java.util.Scanner;

import com.situ.javase.day5.Student;

public class ArrayListStudentManagrer {
	public static void main(String[] args) {
		System.out.println("请输入学生数量");
		Scanner scanner = new Scanner(System.in);
		ArrayList<Student>list = new ArrayList<Student>();
		
		while(true){
			System.out.println("请输入学生id");
			int id = scanner.nextInt();
			System.out.println("请输入学生姓名");
			String name = scanner.next();
			System.out.println("请输入学生年龄");
			int age = scanner.nextInt();
			System.out.println("请输入学生班级");
			String className = scanner.next();
	        Student student = new Student(id, name, age, className);
			list.add(student);
			
			System.out.println("不再输入请按0");
			int quit = scanner.nextInt();
			if (quit == 0) {
				break;
			}
			
	}
		for (Student student : list) {
			System.out.println(student);
		}
		 while (true) {
		        System.out.println("----------------------");
		        System.out.println("根据id查找输入：1");
		        System.out.println("根据名字查找输入：2");
		        System.out.println("根据年龄查找输入：3");
		        System.out.println("根据班级查找输入：4");
		        System.out.println("退出程序：0");
		        System.out.println("----------------------");
		        int type = scanner.nextInt();
		        if (type == 0) {
		           System.out.println("退出程序");
		           break;
		        }
		        
		        switch (type) {
		           case 1:// 根据id查找
		              System.out.println("根据id搜索");
		              System.out.println("请输入id");
		              int SearchId = scanner.nextInt();
		              boolean isSearchByIdFound = false;
		             for (Student student : list) {
						if (student.getId()==SearchId) {
							isSearchByIdFound = true;
							System.out.println(student);
							//break;
						}
					}
		              if (isSearchByIdFound == false) {
						System.out.println("没有该id学生");
					}
		              break;
		           case 2:// 根据名字查找
		              System.out.println("根据名字搜索");
		              System.out.println("请输入姓名");
		              String searchName = scanner.next();
		              boolean isSearchByNameFound = false;
		              // 查找数组里面学生的名字是不是有要和搜索的名字一样，
		              // 1、如果有就打印当前学生的信息，
		              // 2、如果搜索完了所有学生都没有找到，打印“没有该姓名的学生”
		              for (Student student : list) {
		            	  if ( student.getName().equals(searchName)) {
		            		  isSearchByNameFound = true;
		            		  System.out.println(student);
		            		  //break;
		              }
						} if (isSearchByNameFound == false) {
							System.out.println("没有该姓名学生");
						}
		              break;
		              case 3:
		            	  System.out.println("根据年龄搜索");
		            	  System.out.println("请输入年龄");
		            	  int age1 = scanner.nextInt();
		            	  boolean isSearchByAgeFound = false;
		            	for (Student student : list) {
							if (student.getAge()==age1) {
								isSearchByAgeFound = true;
							}
						}if (isSearchByAgeFound == false) {
							System.out.println("没有该年龄学生");
						}
						break;
		              case 4:
		            	  System.out.println("根据班级搜索");
			              System.out.println("请输入班级名");
			              String searchClassName = scanner.next();
			              boolean isSearchByClassNameFound = false;
			              for (Student student : list) {
			            	  if ( student.getClassName().equals(searchClassName)) {
			            		  isSearchByClassNameFound = true;
			            		  System.out.println(student);
			            		  //break;
			              }
							} if (isSearchByClassNameFound == false) {
								System.out.println("没有该班级名学生");
							}
			              break;
	}
	}
	}
}
